package codelib.spring3struts2hibernate3.web.action;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;
import org.springframework.stereotype.Component;

import codelib.spring3struts2hibernate3.biz.UserService;

import com.opensymphony.xwork2.ActionSupport;

@Component("LoginAction")
public class LoginAction extends ActionSupport{
	/**
	 * 
	 */
	private static final long serialVersionUID = -8229463860282685522L;
	
	private UserService userService;
	
	public String login(){
		String lastIp = ServletActionContext.getRequest().getRemoteHost();
		switch (userService.login(lastIp, lastIp, lastIp)) {
		case SUCCESS:
			return SUCCESS;
		case PASSWORD_NOT_MATCH:
		case USER_NOT_VALID:
			return LOGIN;
		case FAILED:
		default:
			return ERROR;
		}
	}
	
	public UserService getUserService() {
		return userService;
	}
	@Resource(name="UserServiceImpl")
	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	
	private String userName;
	private String password;
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
}
